package com.hexb.smh.entity.view;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.LinkedList;
import java.util.List;

/**
 * @author : hexb
 */
@Data
public class ImportResult<T> {

    @ApiModelProperty("总数据条数")
    private Integer total;

    @ApiModelProperty("失败条数")
    private Integer failedTotal;

    @ApiModelProperty("读取文件错误信息")
    private String message;

    private List<FailedItem<T>> failedList = new LinkedList<>();

    @ApiModelProperty("成功条数")
    public Integer getSuccessTotal() {
        return total - failedTotal;
    }

    public void addFailed(T t, String message) {
        this.failedTotal += 1;
        this.failedList.add(new FailedItem<>(t, message));
    }

    public ImportResult() {
        this.total = 0;
        this.failedTotal = 0;
    }

    @Data
    public static class FailedItem<T> {

        private T data;
        private String message;

        public FailedItem(T data, String message) {
            this.data = data;
            this.message = message;
        }
    }
}
